#include <iostream>
#include <string>
#include "structures.hpp"
#include "fileio.hpp"
#include "commands.hpp"
#include "graphics.hpp"

int main() {
    Dataset dataset;
    Graphics graphics;
    std::string command;
    std::string filename;
    bool running = true;

    while (running) {
        std::cout << "请输入命令 (Open/Exit/Save/Query/Area/Stas): ";
        std::cin >> command;

        if (command == "Open") {
            std::cout << "请输入打开的文件名：";
            std::cin >> filename;
            if (openTextFile(filename, dataset)) {
                std::cout << "打开文件成功\n";
                if (graphics.init()) {
                    graphics.drawDataset(dataset);
                    std::cout << "图形窗口已关闭\n";
                }
            } else {
                std::cout << "文件打开不正确\n";
            }
        }
        else if (command == "Save") {
            std::cout << "请输入保存的文件名：";
            std::cin >> filename;
            if (saveToFiles(filename, dataset)) {
                std::cout << "保存文件成功\n";
            } else {
                std::cout << "文件保存不正确\n";
            }
        }
        else if (command == "Query") {
            queryData(dataset);
        }
        else if (command == "Area") {
            calculateAndDisplayAreas(dataset);
        }
        else if (command == "Stas") {
            displayStatistics(dataset);
        }
        else if (command == "Exit") {
            graphics.close();
            running = false;
        }
        else {
            std::cout << "无效命令\n";
        }
    }

    return 0;
} 